
// Copyright (C) 2007 Richard Uhler
// This file is part of Esiply.
//
// Esiply is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, Version 2,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include <assert.h>

#include "InternalFunction.h"
#include "Number.h"
#include "String.h"

InternalFunction::InternalFunction(internal_call_function_t call,
        internal_construct_function_t construct, int params)
    : m_call(call), m_construct(construct)
{
    this->put(new String("length"), new Number((double)params), 
           PA_DONT_ENUM | PA_DONT_DELETE | PA_READ_ONLY);
}

Value* InternalFunction::call(Scope* scope, Value* this_obj, List* args)
{
    // Note: we are intentionally ignoring the scope parameter.
    // TODO: handle this correctly if we don't have a call function implemented
    assert(m_call);
    return (*m_call)(this_obj, args);
}

Value* InternalFunction::construct(List* args)
{
    // TODO: handle this correctly if we don't have a construct function
    // implemented
    assert(m_construct);
    return (*m_construct)(args);
}

